<template>
    <div class="order-completed-container">
      <div class="order-completed-card">
        <h2>订单已完成</h2>
        <div class="order-info">
          <p><strong>订单号:</strong> <span class="order-id">{{ orderNumber }}</span></p>
          <p><strong>完成时间:</strong> <span class="completed-time">{{ completedDate }}</span></p>
          <p><strong>当前时间:</strong> <span class="current-time">{{ currentTime }}</span></p>
          <p><strong>跳转倒计时:</strong> <span class="countdown">{{ countdown }} 秒</span></p>
        </div>
        <button @click="goToHomePage" class="return-btn">返回首页</button>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    name:"OK",
    props: {
      order: {
        type: Object,
        required: true
      }
    },
    data() {
      return {
        orderNumber:241210215113444,
        // 天数比确认收货少两天
        completedDate:(new Date(new Date().getTime() - 2 * 24 * 60 * 60 * 1000)).toLocaleString(),
        currentTime: this.getCurrentTime(),  // 初始时间
        countdown: 3  // 倒计时初始值，3秒
      };
    },
    computed: {
      orderNumber() {
        return this.orderNumber;
      },
      completedDate() {
        return this.completedDate;
      }
    },
    methods: {
      // 获取当前时间的格式
      getCurrentTime() {
        const now = new Date();
        return now.toLocaleString();  // 返回本地时间字符串
      },
      goToHomePage() {
        // 用户点击返回首页时直接跳转
        this.$router.push({ name: 'SystemMessage' });
      }
    },
    mounted() {
      // 每秒更新一次当前时间
      this.timeInterval = setInterval(() => {
        this.currentTime = this.getCurrentTime();  // 更新当前时间
      }, 1000);
  
      // 每秒更新倒计时，直到倒计时结束
      this.countdownInterval = setInterval(() => {
        if (this.countdown > 0) {
          this.countdown -= 1;  // 减少倒计时
        } else {
          clearInterval(this.countdownInterval);  // 倒计时结束，停止更新
          this.$router.push({ name: 'SystemMessage' });  // 自动跳转到系统消息页面
        }
      }, 1000);
    },
    beforeDestroy() {
      // 清除定时器
      clearInterval(this.timeInterval);
      clearInterval(this.countdownInterval);
    }
  };
  </script>
  
  <style scoped>
  .order-completed-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #f0f4f7, #e1e8ed);
    padding: 20px;
  }
  
  .order-completed-card {
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    padding: 30px;
    width: 450px;
    text-align: center;
    transition: transform 0.3s ease-in-out;
  }
  
  .order-completed-card:hover {
    transform: translateY(-5px);
  }
  
  h2 {
    color: #4CAF50;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 1px;
  }
  
  .order-info {
    font-size: 16px;
    color: #333;
    margin-bottom: 25px;
  }
  
  .order-info p {
    margin: 10px 0;
  }
  
  .order-id, .completed-time, .current-time {
    font-weight: 500;
    color: #555;
  }
  
  .countdown {
    font-weight: 600;
    color: #FF5733;  /* 倒计时显示为红色 */
  }
  
  .return-btn {
    padding: 12px 20px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.3s, transform 0.2s;
  }
  
  .return-btn:hover {
    background-color: #45a049;
    transform: scale(1.05);
  }
  
  .return-btn:focus {
    outline: none;
  }
  </style>
  